<?php
/**
 * Модель user_to_user
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveUser
 */

/**
 * Модель user_to_user
 *
 */
class ModelUser_to_user extends Model {
	
	const TABLE				= 'user_to_user';
	const F_USER_ID  	= 'user_id';
	const F_RELATION_ID  	= 'relation_id';
	const F_MODE  	= 'mode';
	const F_SETTINGS  	= 'settings';
	/**
	 * враги
	 *
	 */
	const S_ALIEN=1;
	/**
	 * запрос на дружбу
	 *
	 */
	const S_CONFIRM=2;
	/**
	 * друзья
	 *
	 */
	const S_FRIEND=3;
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='user_to_user';
		$this->id_field=array(self::F_USER_ID,self::F_RELATION_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_USER_ID=> new Field($this,self::F_USER_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>11)),
		self::TABLE.DOT.self::F_RELATION_ID=> new Field($this,self::F_RELATION_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>11,
				'join_table'=>'user')),
		self::TABLE.DOT.self::F_MODE=> new Field($this,self::F_MODE,self::TABLE,array(
				'lenght'=>4)),
		self::TABLE.DOT.self::F_SETTINGS=> new Field($this,self::F_SETTINGS,self::TABLE,array(
				'type'=>Field::TYPE_TEXT))		);
	}
	
	public function create($me,$user,$mode,$settings=""){
	    return $this->save(
          array(
              self::F_MODE=>$mode,
              self::F_USER_ID=>$me,
              self::F_RELATION_ID=>$user,
              self::F_SETTINGS =>$settings
          )
        );
	}
}
